/*
 * @title: 基础配置工具类
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-17 21:17:04
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-04-03 22:25:15
 * @version: 1.0.2
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */

'use strict';
const _path = require('path');
const defaultConfigs = require('./index');

/**
 * @todo: 以__dirname上一级目录为根的拼接路径
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-18 07:46:58
 * @param {array} _vPath
 */
const _join = (..._vPath) => {
  // __dirname: 当前js所在目录下的绝对路径
  const vPath = _path.join(__dirname, '..', ..._vPath);
  return vPath;
};

/**
 * @todo: 以当前文件所在目录为根的绝对路径
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-18 07:50:21
 * @param {array} _vPath
 */
const _resolve = (..._vPath) => {
  const vPath = _path.resolve(__dirname, ..._vPath);
  return vPath;
};

/**
 * @todo: 返回以assert为根目录的拼接路径
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-18 08:39:08
 * @param {array} _vPath
 */
const _assetsPath = (..._vPath) => {
  const vPath = _path.posix.join(defaultConfigs.assetsDir(), ..._vPath);
  return vPath;
};

module.exports = {
  join: (..._path) => _join(..._path),
  resolve: (..._vPath) => _resolve(..._vPath),
  assetsPath: (..._vPath) => _assetsPath(..._vPath)
};
